package net.wicp.tams.plugin.task.docker;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import net.wicp.tams.common.Result;
import net.wicp.tams.common.others.docker.DockerUtil;
import net.wicp.tams.plugin.TaskAssit;

@Mojo(name = "dockpush", requiresProject = false, threadSafe = false)
public class DockPush extends AbstractMojo {
	// apiserver的url
	@Parameter(property = "url", required = false)
	private String url;
	// 要推送的image
	@Parameter(defaultValue = "${project.artifactId}:${project.version}", property = "image", required = false)
	private String image;
	// 要推送的远程库
	@Parameter(property = "rep", required = true)
	private String rep;
	// 要推送的远程tag
	@Parameter(defaultValue = "${project.version}", property = "tag", required = false)
	private String tag;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		TaskAssit.initDockerUrl(url);
		Result ret = DockerUtil.getInst().pushImage(image, rep, tag);
		if (!ret.isSuc()) {
			throw new MojoFailureException("push docker失败：" + ret.getMessage());
		}
	}
}
